package com.cskaoyan.market.service.wx;

import com.cskaoyan.market.db.domain.MarketComment;
import com.cskaoyan.market.db.domain.MarketCommentExample;
import com.cskaoyan.market.db.domain.MarketOrder;
import com.cskaoyan.market.db.domain.MarketOrderExample;
import com.cskaoyan.market.db.mapper.MarketCommentMapper;
import com.cskaoyan.market.db.mapper.MarketOrderMapper;
import com.cskaoyan.market.vo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: chenjian
 * @Date: 2024/5/19 16:32
 */
@Service
public class IndexServiceImpl implements IndexService {
    @Autowired
    MarketCommentMapper marketCommentMapper;
    @Autowired
    MarketOrderMapper marketOrderMapper;
    @Override
    public OrderVo showIndex(Integer userId) {
        int uncomment=0;
        int unpaid=0;
        int unrecv=0;
        int unship=0;

        MarketOrderExample marketOrderExample = new MarketOrderExample();
        MarketOrderExample.Criteria criteria = marketOrderExample.createCriteria();
        criteria.andUserIdEqualTo(userId);
        List<MarketOrder> marketOrders = marketOrderMapper.selectByExample(marketOrderExample);

        MarketCommentExample marketCommentExample = new MarketCommentExample();
        MarketCommentExample.Criteria criteria1 = marketCommentExample.createCriteria();
        criteria1.andUserIdEqualTo(userId);
        List<MarketComment> marketComments = marketCommentMapper.selectByExample(marketCommentExample);
        for (MarketOrder marketOrder : marketOrders) {
            if(marketOrder.getOrderStatus()==101){
                unpaid++;
            }else if(marketOrder.getOrderStatus()==301){
                unrecv++;;
            }else if(marketOrder.getOrderStatus()==201){
                unship++;
            }
        }
        uncomment=marketOrders.size()-marketComments.size();
        OrderVo orderVo =new OrderVo(uncomment,unpaid,unrecv,unship);
        return orderVo;
    }
}
